﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Oracle.DataAccess.Client;
using System.Data;

namespace Urgencias
{
    class extras
    {
        String db = "User id = CLINICA; Password = 123; Data Source = XE;";
        OracleConnection connection = new OracleConnection();
        public void agregarPaciente(string nombre, string apellido, string rut, string edad, string direccion, string isapre, string doctor, string PDA, string telefono, string box, string DC)
        {
            connection.ConnectionString = db;
            connection.Open();
            string sql = "";
            OracleCommand query;
            sql = "INSERT INTO paciente(nombre, apellido, edad, rut, telefono, direccion, box, doctor, DC, PDA, isapre)" +
                "VALUES(:nombre, :apellido, :edad, :rut, :telefono, :direccion, :box, :doctor, :DC, :PDA, :isapre)";
            query = new OracleCommand(sql, connection);
            OracleParameter[] nuevoPa = new OracleParameter[11];

            nuevoPa[0] = query.Parameters.Add("nombre", OracleDbType.Varchar2, nombre, ParameterDirection.Input);
            nuevoPa[1] = query.Parameters.Add("apellido", OracleDbType.Varchar2, apellido, ParameterDirection.Input);
            nuevoPa[2] = query.Parameters.Add("edad", OracleDbType.Varchar2, edad, ParameterDirection.Input);
            nuevoPa[3] = query.Parameters.Add("rut", OracleDbType.Varchar2, rut, ParameterDirection.Input);
            nuevoPa[4] = query.Parameters.Add("telefono", OracleDbType.Varchar2, telefono, ParameterDirection.Input);
            nuevoPa[5] = query.Parameters.Add("direccion", OracleDbType.Varchar2, direccion, ParameterDirection.Input);
            nuevoPa[6] = query.Parameters.Add("box", OracleDbType.Varchar2, box, ParameterDirection.Input);
            nuevoPa[7] = query.Parameters.Add("doctor", OracleDbType.Varchar2, doctor, ParameterDirection.Input);
            nuevoPa[8] = query.Parameters.Add("DC", OracleDbType.Varchar2, DC, ParameterDirection.Input);
            nuevoPa[9] = query.Parameters.Add("PDA", OracleDbType.Varchar2, PDA, ParameterDirection.Input);
            nuevoPa[10] = query.Parameters.Add("isapre", OracleDbType.Varchar2, isapre, ParameterDirection.Input);

            query.ExecuteNonQuery();
            /*MessageBox.Show("Paciente agregado.");
            restablecer();*/
            connection.Close();
        }
        public void modificarPaciente(string nombre, string apellido, string rut, string edad, string direccion, string isapre, string doctor, string PDA, string telefono, string box, string DC)
        {
            connection.ConnectionString = db;
            connection.Open();
            String sql = "UPDATE paciente SET nombre = :nombre, " +
                    "apellido = :apellido, edad = :edad, rut = :rut, telefono = :telefono, " +
                    "direccion = :direccion, box = :box, doctor = :doctor, " +
                    "DC = :DC, PDA = :PDA, isapre = :isapre " +
                "WHERE rut = :rut;";
            //"INSERT INTO paciente(nombre, apellido, edad, rut, telefono, direccion, box, doctor, DC, PDA, isapre)"
            OracleCommand query = new OracleCommand(sql, connection);
            OracleParameter[] modPa = new OracleParameter[11];

            modPa[0] = query.Parameters.Add("nombre", OracleDbType.Varchar2, nombre, ParameterDirection.Input);
            modPa[1] = query.Parameters.Add("apellido", OracleDbType.Varchar2, apellido, ParameterDirection.Input);
            modPa[2] = query.Parameters.Add("edad", OracleDbType.Varchar2, edad, ParameterDirection.Input);
           // modPa[3] = query.Parameters.Add("rut", OracleDbType.Varchar2, rut, ParameterDirection.Input);
            modPa[4] = query.Parameters.Add("telefono", OracleDbType.Varchar2, telefono, ParameterDirection.Input);
            modPa[5] = query.Parameters.Add("direccion", OracleDbType.Varchar2, direccion, ParameterDirection.Input);
            modPa[6] = query.Parameters.Add("box", OracleDbType.Varchar2, box, ParameterDirection.Input);
            modPa[7] = query.Parameters.Add("doctor", OracleDbType.Varchar2, doctor, ParameterDirection.Input);
            modPa[8] = query.Parameters.Add("DC", OracleDbType.Varchar2, DC, ParameterDirection.Input);
            modPa[9] = query.Parameters.Add("PDA", OracleDbType.Varchar2, PDA, ParameterDirection.Input);
            modPa[10] = query.Parameters.Add("isapre", OracleDbType.Varchar2, isapre, ParameterDirection.Input);

            query.ExecuteNonQuery();

            /*MessageBox.Show("Datos Actualizados");
            restablecer();*/
            connection.Close();
        }
        public void eliminarPaciente(string rut)
        {
            connection.ConnectionString = db;
            connection.Open();
            String sql = "DELETE FORM paciente WHERE rut = :rut";
            OracleCommand query = new OracleCommand(sql, connection);

            OracleParameter paciente = query.Parameters.Add("rut", OracleDbType.Varchar2, rut, ParameterDirection.Input);
            query.ExecuteNonQuery();
            connection.Close();
        }
    }
}
